package com.hutu.erp.catalog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hutu.erp.catalog.domain.SpecificationGroup;
import com.hutu.erp.catalog.service.ISpecificationGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品参数组Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@RestController
@RequestMapping("/catalog/specification_group")
public class SpecificationGroupController extends BaseController
{
    @Autowired
    private ISpecificationGroupService specificationGroupService;

    /**
     * 查询商品参数组列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_group:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpecificationGroup specificationGroup)
    {
        startPage();
        List<SpecificationGroup> list = specificationGroupService.selectSpecificationGroupList(specificationGroup);
        return getDataTable(list);
    }

    /**
     * 导出商品参数组列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_group:export')")
    @Log(title = "商品参数组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpecificationGroup specificationGroup)
    {
        List<SpecificationGroup> list = specificationGroupService.selectSpecificationGroupList(specificationGroup);
        ExcelUtil<SpecificationGroup> util = new ExcelUtil<SpecificationGroup>(SpecificationGroup.class);
        return util.exportExcel(list, "商品参数组数据");
    }

    /**
     * 获取商品参数组详细信息
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_group:query')")
    @GetMapping(value = "/{specificationGroupId}")
    public AjaxResult getInfo(@PathVariable("specificationGroupId") Long specificationGroupId)
    {
        return AjaxResult.success(specificationGroupService.selectSpecificationGroupById(specificationGroupId));
    }

    /**
     * 新增商品参数组
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_group:add')")
    @Log(title = "商品参数组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecificationGroup specificationGroup)
    {
        return toAjax(specificationGroupService.insertSpecificationGroup(specificationGroup));
    }

    /**
     * 修改商品参数组
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_group:edit')")
    @Log(title = "商品参数组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecificationGroup specificationGroup)
    {
        return toAjax(specificationGroupService.updateSpecificationGroup(specificationGroup));
    }

    /**
     * 删除商品参数组
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_group:remove')")
    @Log(title = "商品参数组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specificationGroupIds}")
    public AjaxResult remove(@PathVariable Long[] specificationGroupIds)
    {
        return toAjax(specificationGroupService.deleteSpecificationGroupByIds(specificationGroupIds));
    }
}
